#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'num_file file'
exit 1
}

while getopts  ":p:f:s:" opt; do
	case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        s) fs="$OPTARG";;
        *) info;;
	esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

x=`cat $1`
num_max=`echo $x|awk 'BEGIN{RS=" "; ORS="\n"}{print}' |sort -n |sed -n '$p'`

x=$(echo NR==`echo $x|sed 's/ /||NR==/g'`)

awk '{if(NR> '"$num_max"'){exit 0}else{if('"$x"'){print}}}' $2 > $2.sub